package com.tgy.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/***
 * @ClassName: Set
 * @Description: 放置数据到servletcontext
 * @Auther: 送一一块二向箔
 * @Date: 11:07 2021/12/4
 * @version : V1.0
 */
public class Set extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("hello");

        ServletContext servletContext = this.getServletContext();

        String username = "测试";//数据
        servletContext.setAttribute("username",username);//将一个数据保存在ServletContext中  名为：username  值为 测试
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
